package com.ds.seqlist.LeetCode;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author Dianzhi Han
 * @version 1.0
 * @description: TODO
 * @date 2022/9/6 1:29
 */

public class Num232_UseStacksToImplementQueues {
    private Deque<Integer> q1;
    private Deque<Integer> q2;
    public Num232_UseStacksToImplementQueues() {
        q1 = new LinkedList<>();
        q2 = new LinkedList<>();

    }

    public void push(int x) {
        while (!q1.isEmpty()){
            q2.push(q1.pop());
        }
        q2.push(x);
        while (!q2.isEmpty()){
            q1.push(q2.pop());
        }
    }

    public int pop() {
        return q1.pop();
    }

    public int peek() {
        return q1.peek();
    }

    public boolean empty() {
        return q1.isEmpty();
    }
}
